package com.suli.multimedia.controller;


import com.scenic.util.ResponseResult;
import com.suli.multimedia.entity.Note;
import com.suli.multimedia.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author SuLi
 * @since 2022-04-26
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/note")
public class NoteController {

    @Autowired
    NoteService noteService;

    @PostMapping("/insertNote")
    public ResponseResult insertNote(@RequestBody Note note){
        if(noteService.save(note))
        return ResponseResult.ok();
        return ResponseResult.error();
    }

    @GetMapping("/getNoteList/{page}/{limit}")
    public ResponseResult getNotes(@PathVariable Long limit, @PathVariable Long page){
        Map<String, Object> noteList = noteService.getNoteList(page, limit);
        return ResponseResult.ok().data(noteList);
    }

    @DeleteMapping("/deleteNotes")
    public ResponseResult deleteNotes(@RequestBody List<Integer> ids){
        System.out.println(ids);
        if(noteService.removeByIds(ids))
        return ResponseResult.ok().message("删除成功");
        return ResponseResult.error().message("删除失败");
    }
}

